package com.learn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.learn.dto.User;
import com.learn.mapper.UserMapper;
import com.learn.service.impl.UserServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class UserService  implements UserServiceImpl {

    private final UserMapper userMapper;
//    拆线呢全部用户信息
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public List<User> getPage(int pageNum, int pageSize) {
        return userMapper.getPage(pageNum,pageSize);
    }
    @Override
    public User findById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public PageInfo<User> getPageCount(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("分页查询");


        // 执行查询
        List <User> list = userMapper.getPageCount();
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<User> getPageCount(int pageNum, int pageSize, String name, Short gender, String phone, String account, Short status, String deptId, LocalDateTime beginTime, LocalDateTime endTime) {

        // s设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("分页查询");


        // 执行查询
       List <User> list = userMapper.getPageCount(name, gender, phone, account, status, deptId, beginTime, endTime);
        return new PageInfo<>(list);
    }

//    s删除
    @Override
    public int delete(int id) {
        return userMapper.delete(id);
    }

    @Override
    public int deletes(List<Integer> ids) {
        List<Integer> num = userMapper.deletes(ids);
        return 1;
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }
}
